import 'dart:convert';
import 'dart:developer';

import 'package:flutter/foundation.dart';

class ILog {
  static void d(dynamic data, {String? name}) {
    if (!kDebugMode) return;
    _log(toStr(data), name: name);
  }

  static String toStr(dynamic data) {
    if (data is Map) {
      return jsonEncode(data);
    }

    if (data is List) {
      return jsonEncode(data);
    }
    if (data is num) {
      return data.toString();
    }
    if (data is String) {
      return data;
    }
    return data.toString();
  }

  static void l(List<dynamic> data, {String? name}) {
    if (!kDebugMode) return;
    _log(data.map(toStr).join('\n'));
  }

  static _log(String data, {String? name}) {
    log(data, time: DateTime.now(), level: 1, name: name ?? '');
  }
}
